package com.gzlz.budejie.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;

import com.gzlz.budejie.R;

public class HeadView extends RelativeLayout implements View.OnClickListener {

	private View image1;
	private View text;
	private View image2;
	private View image3;

	public HeadView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		image1 = findViewById(R.id.head_image_1);
		image1.setOnClickListener(this);
		text = findViewById(R.id.head_text);
		text.setOnClickListener(this);
		image2 = findViewById(R.id.head_image_2);
		image2.setOnClickListener(this);
		image3 = findViewById(R.id.head_image_3);
		image3.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v==image1) {
			//TODO 启动标签订阅界面
			
		}
		if (v==image2||v==text) {
			startHeadImage2RotateAnimation();
			//TODO 调用正在展示中的listView刷新
			
		}
		if (v==image3) {
			//TODO 随机穿越 
			
		}
	}
	
	public void startHeadImage2RotateAnimation(){
		RotateAnimation animation = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
		animation.setDuration(800);
		animation.setInterpolator(new  LinearInterpolator());
		animation.setFillBefore(true);
		animation.setRepeatCount(Integer.MAX_VALUE);
		image2.startAnimation(animation);
	}
	
	public void stopHeadImage2RotateAnimation(){
		image2.clearAnimation();
	}
	
}
